package com.igoal.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name = "user_status")
public class UserStatus extends BaseObject implements Audit, Serializable, ItemOwner {
	private static final long serialVersionUID = -6609042677918040878L;

	private Long id;
	private String userStatus;
	private Image smiley;
	private DataStatus status;
	private Date createDate;
	private Date updateDate;
	
	private User user;

//	@OneToOne(fetch = FetchType.LAZY)
//	@PrimaryKeyJoinColumn
//	public User getUser() {
//		return user;
//	}
//
	public void setUser(User user) {
		this.user = user;
	}
	
	@ManyToOne
	@JoinColumn(name="user_id")
	public User getUser() {
		return this.user;
	}

//	@GeneratedValue(generator = "system-foreign")
//	@GenericGenerator(name = "system-foreign", strategy = "foreign", parameters = @Parameter(name = "property", value = "user"))
//	@Id
//	@SearchableId
//	@Column(name = "id", unique = true, nullable = false)
//	public Long getId() {
//		return id;
//	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@SearchableId
	public Long getId(){
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "user_status", nullable = true)
	public String getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(String userStatus) {
		this.userStatus = userStatus;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "smiley")
	public Image getSmiley() {
		return this.smiley;
	}

	public void setSmiley(Image smiley) {
		this.smiley = smiley;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, name = "cdate")
	public Date getCreateDate() {
		return createDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, name = "mdate")
	public Date getUpdateDate() {
		return updateDate;
	}

	public void setCreateDate(Date date) {
		this.createDate = date;
	}

	public void setUpdateDate(Date date) {
		this.updateDate = date;
	}

	@Override
	public boolean equals(Object o) {
		if (o != null && o instanceof UserStatus) {
			UserStatus target = (UserStatus) o;
			return getId().equals(target.getId());
		}
		return false;
	}

	@Override
	public int hashCode() {
		return getId().hashCode();
	}

	@Override
	public String toString() {
		return getUserStatus();
	}

	@Enumerated(EnumType.STRING)
	@Column(nullable = true, name = "status")
	@SearchableProperty
	public DataStatus getStatus() {
		return status;
	}

	public void setStatus(DataStatus dataStatus) {
		this.status = dataStatus;
	}

	@Transient
	public User getOwner() {
		return user;
	}
}
